﻿using Maticsoft.DBUtility;
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;

namespace Maticsoft222.DAL
{
    public class sqlexec
    {
        public bool ExecuteSql(string sql)
        {
            return DbHelperSQL.ExecuteSql(sql) > 0;
        }
        public DataSet query(string sql)
        {
            return DbHelperSQL.Query(sql);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Maticsoft222.Model.sqlex> exsql(string sql)
        {
            return model(DbHelperSQL.Query(sql));
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Maticsoft222.Model.sqlex> excodesql(string sql)
        {
            return modelcode(DbHelperSQL.Query(sql));
        }
        private List<Maticsoft222.Model.sqlex> model(DataSet ds)
        {
            List<Maticsoft222.Model.sqlex> list = new List<Model.sqlex>();
            if (ds != null && ds.Tables[0] != null)
            {
                foreach (DataRow item in ds.Tables[0].Rows)
                {
                    Model.sqlex s = new Model.sqlex();
                    s.Code = item["parentcode"].ToString();
                    s.Name = item["parentname"].ToString();
                    list.Add(s);
                }
            }
            return list;
        }
        private List<Maticsoft222.Model.sqlex> modelcode(DataSet ds)
        {
            List<Maticsoft222.Model.sqlex> list = new List<Model.sqlex>();
            if (ds != null && ds.Tables[0] != null)
            {
                foreach (DataRow item in ds.Tables[0].Rows)
                {
                    Model.sqlex s = new Model.sqlex();
                    s.Code = item["code"].ToString();
                    s.Name = item["name"].ToString();
                    list.Add(s);
                }
            }
            return list;
        }
    }
}
